#ifndef __LCD_ST7735S_GUI_H
#define __LCD_ST7735S_GUI_H


#include "myDriverConfig.h"
#include <stdlib.h>
#include <stdio.h>
#define FIRST_LINE 2
#define SECOND_LINE 70
#define KEYCS_Y 107
// extern uint8_t *cs[4];
/*
 * 菜单结构体：
 *
 */
typedef struct MENU_1{
	uint8_t hang;   //第几行，1~8行
    uint8_t *str;      // 菜单内容
    
}MENU_ONE;



typedef struct{
    uint8_t hang;
    MENU_ONE x[7];
}MENU_2;

typedef enum{
    A = 1,
    B,
    C,
    D,
    E,
}CLEAR_SUM;

typedef struct DoublyLinkedList DoublyLinkedList;
typedef struct MENU_FRIST MENU_Frist;

/* 菜单链结构体
 */
struct MENU_FRIST{
    uint8_t hang;
    uint16_t angle;//用于给二级菜单赋值
    uint16_t qishix;//数据域起始行
    uint8_t *str;
    MENU_Frist *last;//指向前一个节点的指针
    MENU_Frist *next;//指向下一个节点的指针
    DoublyLinkedList *nextList;//下一级菜单
};

// 定义带头双向链表
typedef struct DoublyLinkedList {
    MENU_Frist* head;  // 头节点，不存储数据
} DoublyLinkedList;




// 按钮控件结构体
typedef struct {
    uint16_t x, y, w, h;
    const char *label;
    void (*callback)(void);
} Button;


//菜单抽象
//一级ui
typedef struct kkk MENU_SUM2;
struct kkk{
    uint8_t h;//总共有多少行
    //左边为4个汉字，即16*4=64的长度
    MENU_ONE *x[7];
    MENU_SUM2 *next[7];//下一级菜单
} ;

void CheckButtonClick(Button *btn, uint16_t key);
void DrawButton(Button *btn, unsigned short bg_color, unsigned short text_color);
//渲染初级界面
void GUI_Init(DoublyLinkedList* list);
//设置4各白色按键提示
void GUI_DisplayKeyCsInit(void);
//设置对应的按键是高亮还是恢复白色
void GUI_DisplayKeyCs(uint8_t key,uint8_t flag);
//遍历一级菜单
void GUI_DisplayMenu(DoublyLinkedList* list);
/* 
 * 打印无限模式的度数设置
 * 参数（DoublyLinkedList* list）：需要打印的链表
 * 参数（uint8_t mode）：模式0或1,2，决定打印的模式
 */
void GUI_PrintWUXIANMODE_angele(DoublyLinkedList* list, uint8_t mode);
/* 开始后的打印：无限模式 */
void GUI_StartDisplay(DoublyLinkedList* list);
/* 
 * 开始后的打印：圈数模式
 */
void GUI_StartDisplayQ(DoublyLinkedList* list);
void GUI_1stMenu(MENU_ONE *x,uint8_t num);
void GUI_LEFT_CS(MENU_SUM2 x);
void btn1(void);


/* 实现滚动
 * 定义ABCDE块的起始点
 */
#define A_x 2
#define A_y 2
#define B_x 2
#define B_y 18
#define C_x 2
#define C_y 44
#define D_x 2
#define D_y 68
#define E_x 2
#define E_y 86

#define A2_y 2
#define A2_x 70



void initList(DoublyLinkedList* list);
void insertAtBeginning(DoublyLinkedList* list, uint8_t hang, uint16_t  qishix,uint16_t angle,uint8_t *str,DoublyLinkedList* nextlist);
void insertAtEnd(DoublyLinkedList* list, uint8_t hang, uint16_t  qishix,uint16_t angle ,uint8_t *str,DoublyLinkedList* nextlist);
void GUI_DisplayOn(CLEAR_SUM Clear_number,uint8_t *str);
uint8_t GUI_key_up(DoublyLinkedList* list,uint8_t key);
uint8_t GUI_key_down(DoublyLinkedList* list,uint8_t key);
void GUI_key_enter(DoublyLinkedList* list,uint8_t key);
void GUI_key_disenter(DoublyLinkedList* list,uint8_t key);
void GUI_DisplayMenu2(DoublyLinkedList* list, uint8_t mode);
#endif

